package LeetcodeTest_twenty_seven;
//判断是不是二叉搜索树

import java.util.ArrayList;
import java.util.Scanner;

public class isValidBST
{
    public static void main(String[] args)
    {
        TreeNode root=null;
        root=solution.createTree(root);
        System.out.println(solution.isValidBST(root));
    }
}
class solution
{
    public static boolean isValidBST(TreeNode root)
    {
        boolean flag=true;
        ArrayList<Integer> nums=new ArrayList<Integer>();
        difs(root,nums);
        for(int i=0;i<nums.size()-1;i++)
        {
            if (nums.get(i) >= nums.get(i + 1))
                flag = false;
        }
        return flag;
    }
    public static void difs(TreeNode T,ArrayList<Integer> nums)
    {
        if(T!=null)
        {
            difs(T.left,nums);
            nums.add(T.val);
            difs(T.right,nums);
        }
    }
    public static TreeNode createTree(TreeNode T)
    {
        Scanner reader=new Scanner(System.in);
        int a=reader.nextInt();
        TreeNode p=null;
        if (a==-1)
            p=null;
        else
            p = new TreeNode(a);
        T=p;
        if(T==null)
            return T;
        else
        {
            T.left = createTree(T.left);
            T.right = createTree(T.right);
        }
        return T;
    }
}
